// pages/akchepiao/akchepiao.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    POST_SENT_HOME_NAME: '',
    POST_SENT_HOME_PHONE: '',
    POST_SENT_HOME_ADDRESS:'',
    L3name: '',
    L4name: '',
    tankuang: true,
    shi_q: true,
    shi_w: true,
    shi_chun: true,
    chunname:'春联',

    chunlian:[
      {
        saix:"小"
      },
      {
        saix:"中"
      },
      {
        saix:"大"
      },
    ],
    flag: true, //设置节流
  },



  quxian() {
    this.setData({
      shi_q: false,
    })
  },

  wangdian() {

    this.setData({
      shi_w: false,
    })

  },


  chunlian() {
    this.setData({
      shi_chun: false,
    })
  },







  region() {
    wx.request({
      url: app.globalData.interface+'/ankangdabiao/API_5515_userQueryQuXian',
      method: 'POST',
      data: {
        L2code:61000077,
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        console.log(res.data.data);
        this.setData({
          city: res.data.data,
        })

      }
    })
  },


  buttn_a(e) {
    console.log(e);
    console.log(e.currentTarget.dataset.item.saix);

    this.setData({
     
      chunname: e.currentTarget.dataset.item.saix,
      shi_chun: true
    })
  },



  buttn_c(e) {
    console.log(e);
    console.log(e.currentTarget.dataset.item.L3name);
    console.log(e.currentTarget.dataset.item.L3code);
    this.setData({
      L3code: e.currentTarget.dataset.item.L3code,
      L3name: e.currentTarget.dataset.item.L3name,
      shi_q: true,
      L4name:'',
    })
  },


  buttn_d(e) {
    console.log(e);
    console.log(e.currentTarget.dataset.item.L4name);
    this.setData({
      L4name: e.currentTarget.dataset.item.L4name,
      shi_w: true
    })
  },



  //网点
  Outlets() {

    if (this.data.L3name == '') {
      wx.showToast({
        icon: 'none',
        title: '请先选择区县',
        duration: 1800
      })
    } else {

      wx.request({
        url: app.globalData.interface+'/ankangdabiao/API_5517_userQueryWangDian',
        method: 'POST',
        data: {

          L3code: this.data.L3code
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: res => {
          this.setData({
            shi_w: false,
          })
          console.log(res);
          console.log(res.data.data);
          this.setData({
            business: res.data.data
          })

        }
      })


    }
  },











  shuju_c() {
 

    if (this.data.flag) {
      this.data.flag = false

    if (this.data.POST_SENT_HOME_NAME == "" || this.data.POST_SENT_HOME_PHONE == "" || this.data.L3name == "" || this.data.L4name == "" || this.data.chunname == ""||this.data.POST_SENT_HOME_ADDRESS=='') {
      wx.showToast({
        title: '请完善报名信息',
        icon: 'none',
        duration: 1500
      })
    } else {
      wx.request({
        url: app.globalData.interface+'/xianyangTicket/API_1801_addPostSentUser',
        method: 'POST',
        data: {
          POST_SENT_HOME_ADDRESS: this.data.POST_SENT_HOME_ADDRESS,
          POST_SENT_HOME_NAME: this.data.POST_SENT_HOME_NAME,
          POST_SENT_HOME_PHONE: this.data.POST_SENT_HOME_PHONE,
          COUNTY: this.data.L3name,
          NETWORK: this.data.L4name,
          SPRING_FESTIVAL_COUPLETS: this.data.chunname,
          OPEN_ID:this.data.OPEN_ID, //用户OPEN_ID
          session_key: this.data.session_key,
          OPEN_UUID: this.data.jiami,
          
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: res => {
          console.log(res.data.result);

          if (res.data.result == 'success') {
            console.log(res.data.postSentHomeUser);

            this.setData({
              shoushu: res.data,
              tankuang: true,
            })

            wx.showToast({
              title: '恭喜报名成功！！！',
              icon: 'none',
              duration: 1500
            })
            // wx.navigateTo({
            //   url: '../../pages/akchepiaozhuan/akchepiaozhuan?data=' + JSON.stringify(this.data.shoushu)
            // })
          } else {

            wx.showToast({
              title: res.data.data,
              icon: 'none',
              duration: 1500
            })

          }


        }
      })
    }
    setTimeout(() => {
      this.data.flag = true
    }, 5000)
  }
  },



  buttan() {
    this.setData({
      tankuang: false
    })
    this.setData({
      jiami: app.globalData.jiami,
      OPEN_ID: app.globalData.openid,
      session_key: app.globalData.session_key,

    })
    console.log(this.data.jiami);
  },

  nozhuce() {
    this.setData({
      tankuang: true,
      shi_q: true,
      shi_w: true,
      shi_chun:true,
      

    })
  },



  //验证手机号
  mobileInput(e) {
    let value = e.detail.value.replace(/\D/g, '')
    this.setData({
      mobile: value,
    })
    // var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(19[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
    var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(19[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
    if (this.data.mobile.length == 0) {
      wx.showToast({
        title: '输入的手机号为空，请重新输入！',
        icon: 'none',
        duration: 1500
      })
      this.setData({
        mobileFormat: false,
        POST_SENT_HOME_PHONE: '',
      })
    } else if (this.data.mobile.length < 11) {

      wx.showToast({
        title: '手机号长度有误，请重新输入！',
        icon: 'none',
        duration: 1500
      })
      this.setData({
        POST_SENT_HOME_PHONE: '',
        mobileFormat: false,
      })

    } else if (!myreg.test(this.data.mobile)) {
      wx.showToast({
        title: '手机号有误，请重新输入！',
        icon: 'none',
        duration: 1500
      })
      this.setData({
        POST_SENT_HOME_PHONE: '',
        mobileFormat: false,
      })

    } else {
      this.setData({
        mobileFormat: true,

      })
    }
  },







  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      jiami: app.globalData.jiami,
      OPEN_ID: app.globalData.openid,
      session_key: app.globalData.session_key,

    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.region()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})